<!DOCTYPE HTML>
<html lang="zh-hans">

<head>
  <meta charset="UTF-8">
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  <title>高频算法 · 码路大前端小册-企业面试真题</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="description" content="">
  <meta name="generator" content="GitBook 3.2.3">
  <meta name="author" content="码路">



  <link rel="stylesheet" href="../gitbook/style.css">




  <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">



  <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">



  <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">



  <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">



  <link rel="stylesheet" href="../gitbook/gitbook-plugin-insert-logo/plugin.css">



  <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">



  <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">



  <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">















  <meta name="HandheldFriendly" content="true" />
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <link rel="apple-touch-icon-precomposed" sizes="152x152"
    href="../gitbook/images/apple-touch-icon-precomposed-152.png">
  <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">


  <link rel="next" href="../others/" />


  <link rel="prev" href="../handwritten/" />



  <link rel="shortcut icon" href='../source/images/favicon.jpg' type="image/x-icon">


  <link rel="bookmark" href='../source/images/favicon.jpg' type="image/x-icon">


  <link rel="apple-touch-icon" href='../source/images/apple-touch-icon.jpg'>



  <link rel="apple-touch-icon" sizes="120x120" href="../source/images/apple-touch-icon.jpg">

  <link rel="apple-touch-icon" sizes="180x180" href="../source/images/apple-touch-icon.jpg">



  <style>
    @media only screen and (max-width: 640px) {
      .book-header .hidden-mobile {
        display: none;
      }
    }
  </style>
  <script>
    window["gitbook-plugin-github-buttons"] = { "buttons": [{ "user": "lurongtao", "repo": "felixbooks-interview", "type": "star", "size": "small", "count": true }] };
  </script>

</head>

<body>

  <div class="book">
    <div class="book-summary">


      <div id="book-search-input" role="search">
        <input type="text" placeholder="输入并搜索" />
      </div>


      <nav role="navigation">



        <ul class="summary">









          <li class="chapter " data-level="1.1" data-path="../">

            <a href="../">


              前言

            </a>



          </li>

          <li class="chapter " data-level="1.2" data-path="../HTML+CSS/">

            <a href="../HTML+CSS/">


              HTML5+CSS3

            </a>



          </li>

          <li class="chapter " data-level="1.3" data-path="../javascript/">

            <a href="../javascript/">


              JavaScript

            </a>



          </li>

          <li class="chapter " data-level="1.4" data-path="../node/">

            <a href="../node/">


              Node.js

            </a>



          </li>

          <li class="chapter " data-level="1.5" data-path="../vue/">

            <a href="../vue/">


              Vue.js

            </a>



          </li>

          <li class="chapter " data-level="1.6" data-path="../react/">

            <a href="../react/">


              React

            </a>



          </li>

          <li class="chapter " data-level="1.7" data-path="../weapp/">

            <a href="../weapp/">


              小程序

            </a>



          </li>

          <li class="chapter " data-level="1.8" data-path="../browser/">

            <a href="../browser/">


              浏览器

            </a>



          </li>

          <li class="chapter " data-level="1.9" data-path="../network/">

            <a href="../network/">


              网络

            </a>



          </li>

          <li class="chapter " data-level="1.10" data-path="../engineering/">

            <a href="../engineering/">


              前端工程化

            </a>



          </li>

          <li class="chapter " data-level="1.11" data-path="../performance/">

            <a href="../performance/">


              性能

            </a>



          </li>

          <li class="chapter " data-level="1.12" data-path="../security/">

            <a href="../security/">


              安全

            </a>



          </li>

          <li class="chapter " data-level="1.13" data-path="../handwritten/">

            <a href="../handwritten/">


              手写代码

            </a>



          </li>

          <li class="chapter active" data-level="1.14" data-path="./">

            <a href="./">


              高频算法

            </a>



          </li>

          <li class="chapter " data-level="1.15" data-path="../others/">

            <a href="../others/">


              综合

            </a>



          </li>




          <li class="divider"></li>



          <li class="chapter " data-level="2.1" data-path="../thanks/">

            <a href="../thanks/">


              感谢

            </a>



          </li>




          <li class="divider"></li>

          <li>
            <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
              本书使用 GitBook 发布
            </a>
          </li>
        </ul>


      </nav>


    </div>

    <div class="book-body">

      <div class="body-inner">



        <div class="book-header" role="navigation">


          <!-- Title -->
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i>
            <a href="..">高频算法</a>
          </h1>
        </div>




        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <div id="book-search-results">
              <div class="search-noresults">

                <section class="normal markdown-section">

                  <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i>
                    <ul>
                      <li><span class="title-icon "></span><a href="#&#x76EE;&#x5F55;"><b></b>&#x76EE;&#x5F55;</a></li>
                      <li><span class="title-icon "></span><a
                          href="#&#x9AD8;&#x9891;&#x7B97;&#x6CD5;&#x9762;&#x8BD5;&#x771F;&#x9898;"><b></b>&#x9AD8;&#x9891;&#x7B97;&#x6CD5;&#x9762;&#x8BD5;&#x771F;&#x9898;</a>
                      </li>
                      <ul>
                        <ul>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;&#x2605;-&#x5192;&#x6CE1;&#x6392;&#x5E8F;"><b></b>&#x2605;&#x2605;&#x2605;
                              &#x5192;&#x6CE1;&#x6392;&#x5E8F;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;-&#x9009;&#x62E9;&#x6392;&#x5E8F;"><b></b>&#x2605;&#x2605;
                              &#x9009;&#x62E9;&#x6392;&#x5E8F;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;-&#x63D2;&#x5165;&#x6392;&#x5E8F;"><b></b>&#x2605;&#x2605;
                              &#x63D2;&#x5165;&#x6392;&#x5E8F;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;-&#x5E0C;&#x5C14;&#x6392;&#x5E8F;"><b></b>&#x2605;&#x2605;
                              &#x5E0C;&#x5C14;&#x6392;&#x5E8F;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;-&#x5F52;&#x5E76;&#x6392;&#x5E8F;"><b></b>&#x2605;&#x2605;
                              &#x5F52;&#x5E76;&#x6392;&#x5E8F;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;&#x2605;-&#x5FEB;&#x901F;&#x6392;&#x5E8F;"><b></b>&#x2605;&#x2605;&#x2605;
                              &#x5FEB;&#x901F;&#x6392;&#x5E8F;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;-&#x5806;&#x6392;&#x5E8F;"><b></b>&#x2605;&#x2605;
                              &#x5806;&#x6392;&#x5E8F;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;&#x2605;-&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;"><b></b>&#x2605;&#x2605;&#x2605;
                              &#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;-&#x6C49;&#x8BFA;&#x5854;&#x95EE;&#x9898;"><b></b>&#x2605;&#x2605;
                              &#x6C49;&#x8BFA;&#x5854;&#x95EE;&#x9898;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;-&#x5408;&#x5E76;&#x4E24;&#x4E2A;&#x6709;&#x5E8F;&#x6570;&#x7EC4;"><b></b>&#x2605;&#x2605;
                              &#x5408;&#x5E76;&#x4E24;&#x4E2A;&#x6709;&#x5E8F;&#x6570;&#x7EC4;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;-&#x6570;&#x7EC4;&#x4E2D;&#x91CD;&#x590D;&#x7684;&#x6570;&#x5B57;"><b></b>&#x2605;&#x2605;
                              &#x6570;&#x7EC4;&#x4E2D;&#x91CD;&#x590D;&#x7684;&#x6570;&#x5B57;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;-&#x4E24;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x4EA4;&#x96C6;"><b></b>&#x2605;&#x2605;
                              &#x4E24;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x4EA4;&#x96C6;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;-&#x65CB;&#x8F6C;&#x6570;&#x7EC4;"><b></b>&#x2605;&#x2605;
                              &#x65CB;&#x8F6C;&#x6570;&#x7EC4;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;-&#x4E24;&#x6570;&#x4E4B;&#x548C;"><b></b>&#x2605;&#x2605;
                              &#x4E24;&#x6570;&#x4E4B;&#x548C;</a></li>
                          <li><span class="title-icon "></span><a
                              href="#&#x2605;&#x2605;-&#x722C;&#x53F0;&#x9636;&#x7684;&#x5B9E;&#x73B0;&#x601D;&#x8DEF;"><b></b>&#x2605;&#x2605;
                              &#x722C;&#x53F0;&#x9636;&#x7684;&#x5B9E;&#x73B0;&#x601D;&#x8DEF;</a></li>
                        </ul>
                      </ul>
                    </ul>
                  </div><a href="#&#x76EE;&#x5F55;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a>
                  <h1 id="&#x76EE;&#x5F55;"><a name="&#x76EE;&#x5F55;" class="anchor-navigation-ex-anchor"
                      href="#&#x76EE;&#x5F55;"><i class="fa fa-link" aria-hidden="true"></i></a><a
                      name="&#x76EE;&#x5F55;" class="plugin-anchor" href="#&#x76EE;&#x5F55;"><i class="fa fa-link"
                        aria-hidden="true"></i></a>&#x76EE;&#x5F55;</h1>
                  <p><a href="#algorithm-1">&#x2605;&#x2605;&#x2605; &#x5192;&#x6CE1;&#x6392;&#x5E8F;</a></p>
                  <p><a href="#algorithm-2">&#x2605;&#x2605; &#x9009;&#x62E9;&#x6392;&#x5E8F;</a></p>
                  <p><a href="#algorithm-3">&#x2605;&#x2605; &#x63D2;&#x5165;&#x6392;&#x5E8F;</a></p>
                  <p><a href="#algorithm-4">&#x2605;&#x2605; &#x5E0C;&#x5C14;&#x6392;&#x5E8F;</a></p>
                  <p><a href="#algorithm-5">&#x2605;&#x2605; &#x5F52;&#x5E76;&#x6392;&#x5E8F;</a></p>
                  <p><a href="#algorithm-6">&#x2605;&#x2605;&#x2605; &#x5FEB;&#x901F;&#x6392;&#x5E8F;</a></p>
                  <p><a href="#algorithm-7">&#x2605;&#x2605; &#x5806;&#x6392;&#x5E8F;</a></p>
                  <p><a href="#algorithm-8">&#x2605;&#x2605;&#x2605;
                      &#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;</a></p>
                  <p><a href="#algorithm-9">&#x2605;&#x2605; &#x6C49;&#x8BFA;&#x5854;&#x95EE;&#x9898;</a></p>
                  <p><a href="#algorithm-10">&#x2605;&#x2605;
                      &#x5408;&#x5E76;&#x4E24;&#x4E2A;&#x6709;&#x5E8F;&#x6570;&#x7EC4;</a></p>
                  <p><a href="#algorithm-11">&#x2605;&#x2605;
                      &#x6570;&#x7EC4;&#x4E2D;&#x91CD;&#x590D;&#x7684;&#x6570;&#x5B57;</a></p>
                  <p><a href="#algorithm-12">&#x2605;&#x2605;
                      &#x4E24;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x4EA4;&#x96C6;</a></p>
                  <p><a href="#algorithm-13">&#x2605;&#x2605; &#x65CB;&#x8F6C;&#x6570;&#x7EC4;</a></p>
                  <p><a href="#algorithm-14">&#x2605;&#x2605; &#x4E24;&#x6570;&#x4E4B;&#x548C;</a></p>
                  <p><a href="#algorithm-15">&#x2605;&#x2605;
                      &#x722C;&#x53F0;&#x9636;&#x7684;&#x5B9E;&#x73B0;&#x601D;&#x8DEF;</a></p>
                  <h1 id="&#x9AD8;&#x9891;&#x7B97;&#x6CD5;&#x9762;&#x8BD5;&#x771F;&#x9898;"><a
                      name="&#x9AD8;&#x9891;&#x7B97;&#x6CD5;&#x9762;&#x8BD5;&#x771F;&#x9898;"
                      class="anchor-navigation-ex-anchor"
                      href="#&#x9AD8;&#x9891;&#x7B97;&#x6CD5;&#x9762;&#x8BD5;&#x771F;&#x9898;"><i class="fa fa-link"
                        aria-hidden="true"></i></a><a
                      name="&#x9AD8;&#x9891;&#x7B97;&#x6CD5;&#x9762;&#x8BD5;&#x771F;&#x9898;" class="plugin-anchor"
                      href="#&#x9AD8;&#x9891;&#x7B97;&#x6CD5;&#x9762;&#x8BD5;&#x771F;&#x9898;"><i class="fa fa-link"
                        aria-hidden="true"></i></a>&#x9AD8;&#x9891;&#x7B97;&#x6CD5;&#x9762;&#x8BD5;&#x771F;&#x9898;</h1>
                  <h3 id="&#x2605;&#x2605;&#x2605;-&#x5192;&#x6CE1;&#x6392;&#x5E8F;"><a
                      name="&#x2605;&#x2605;&#x2605;-&#x5192;&#x6CE1;&#x6392;&#x5E8F;"
                      class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;&#x2605;-&#x5192;&#x6CE1;&#x6392;&#x5E8F;"><i class="fa fa-link"
                        aria-hidden="true"></i></a><a name="&#x2605;&#x2605;&#x2605;-&#x5192;&#x6CE1;&#x6392;&#x5E8F;"
                      class="plugin-anchor" href="#&#x2605;&#x2605;&#x2605;-&#x5192;&#x6CE1;&#x6392;&#x5E8F;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-1">&#x2605;&#x2605;&#x2605; &#x5192;&#x6CE1;&#x6392;&#x5E8F;</p>
                  </h3>
                  <blockquote>
                    <p>
                      &#x4ECE;&#x5F00;&#x59CB;&#x4F4D;&#x7F6E;&#x4E24;&#x4E24;&#x6BD4;&#x8F83;&#xFF0C;&#x6301;&#x7EED;n&#x8F6E;
                    </p>
                  </blockquote>
                  <ul>
                    <li>
                      <h4 id="&#x57FA;&#x7840;&#x7248;"><a name="&#x57FA;&#x7840;&#x7248;"
                          class="anchor-navigation-ex-anchor" href="#&#x57FA;&#x7840;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="&#x57FA;&#x7840;&#x7248;" class="plugin-anchor"
                          href="#&#x57FA;&#x7840;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x57FA;&#x7840;&#x7248;</h4>
                      <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bubbleSort</span> (<span class="hljs-params">arr</span>) </span>{
<span class="hljs-comment">// &#x6267;&#x884C;&#x7B2C; i + 1 &#x8F6E;</span>
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; arr.length; i++) {
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>; j &lt; arr.length - <span class="hljs-number">1</span>; j++) {
    <span class="hljs-comment">// &#x524D;&#x4E00;&#x4E2A;&#x4E0E;&#x540E;&#x4E00;&#x4E2A;&#x4E24;&#x4E24;&#x6BD4;&#x8F83;</span>
    <span class="hljs-keyword">if</span> (arr[j] &gt; arr[j + <span class="hljs-number">1</span>]) {
      <span class="hljs-comment">// &#x4EA4;&#x6362;&#x4E24;&#x4E2A;&#x53D8;&#x91CF;&#x503C;</span>
      <span class="hljs-keyword">let</span> tmp = arr[j]
      arr[j] = arr[j + <span class="hljs-number">1</span>]
      arr[j + <span class="hljs-number">1</span>] = tmp
    }
  }
}
}
</code></pre>
                    </li>
                    <li>
                      <h4 id="&#x6539;&#x8FDB;&#x7248;"><a name="&#x6539;&#x8FDB;&#x7248;"
                          class="anchor-navigation-ex-anchor" href="#&#x6539;&#x8FDB;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="&#x6539;&#x8FDB;&#x7248;" class="plugin-anchor"
                          href="#&#x6539;&#x8FDB;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x6539;&#x8FDB;&#x7248;</h4>
                      <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">bubbleSort</span> (<span class="hljs-params">arr</span>) </span>{
<span class="hljs-comment">// &#x5192;&#x6CE1;&#x6BCF;&#x6B21;&#x5904;&#x7406;&#x4E2A;&#x6700;&#x5927;/&#x6700;&#x5C0F;&#x503C;, i &#x4EE3;&#x8868;&#x6BCF;&#x6B21;&#x6700;&#x5927;&#x503C;&#x7684;&#x4F4D;&#x7F6E;</span>
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = arr.length - <span class="hljs-number">1</span>; i &gt; <span class="hljs-number">0</span>; i--) {
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>; j &lt; i; j++) {
    <span class="hljs-keyword">if</span> (arr[j] &gt; arr[j + <span class="hljs-number">1</span>]) {
      <span class="hljs-comment">// &#x4EA4;&#x6362;&#x4E24;&#x4E2A;&#x53D8;&#x91CF;&#x503C;</span>
      [arr[j], arr[j + <span class="hljs-number">1</span>]] = [arr[j + <span class="hljs-number">1</span>], arr[j]]
    }
  }
}
}
</code></pre>
                    </li>
                  </ul>
                  <h3 id="&#x2605;&#x2605;-&#x9009;&#x62E9;&#x6392;&#x5E8F;"><a
                      name="&#x2605;&#x2605;-&#x9009;&#x62E9;&#x6392;&#x5E8F;" class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;-&#x9009;&#x62E9;&#x6392;&#x5E8F;"><i class="fa fa-link"
                        aria-hidden="true"></i></a><a name="&#x2605;&#x2605;-&#x9009;&#x62E9;&#x6392;&#x5E8F;"
                      class="plugin-anchor" href="#&#x2605;&#x2605;-&#x9009;&#x62E9;&#x6392;&#x5E8F;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-2">&#x2605;&#x2605; &#x9009;&#x62E9;&#x6392;&#x5E8F;</p>
                  </h3>
                  <blockquote>
                    <p>&#x6BCF;&#x6B21;&#x9009;&#x51FA;&#x6700;&#x5927;/&#x6700;&#x5C0F;&#x503C;
                      &#x6301;&#x7EED;n&#x8F6E;</p>
                  </blockquote>
                  <ul>
                    <li>
                      <h4 id="&#x57FA;&#x7840;&#x7248;_1"><a name="&#x57FA;&#x7840;&#x7248;_1"
                          class="anchor-navigation-ex-anchor" href="#&#x57FA;&#x7840;&#x7248;_1"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="&#x57FA;&#x7840;&#x7248;" class="plugin-anchor"
                          href="#&#x57FA;&#x7840;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x57FA;&#x7840;&#x7248;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">selectSort</span> (<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-comment">// &#x6BCF;&#x6B21;&#x7684;&#x6700;&#x5C0F;&#x503C;&#x7684;&#x7D22;&#x5F15;</span>
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len_i = arr.length; i &lt; len_i; i++) {
    <span class="hljs-comment">// &#x6BCF;&#x8F6E;&#x6700;&#x5C0F;&#x503C;&#x7D22;&#x5F15;</span>
    <span class="hljs-keyword">let</span> index = i

    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = i, len_j = arr.length; j &lt; len_j; j++) {
      <span class="hljs-keyword">if</span> (arr[index] &gt; arr[j]) {
        <span class="hljs-comment">// &#x6700;&#x5C0F;&#x503C;&#x53D8;&#x5316;</span>
        index = j
      }
    }
    <span class="hljs-comment">// &#x628A;&#x6700;&#x5C0F;&#x503C;&#x653E;&#x5230;&#x7B2C; i &#x7684;&#x7D22;&#x5F15;</span>
    [arr[i], arr[index]] = [arr[index], arr[i]]
  }
}
</code></pre>
                  <ul>
                    <li>
                      <h4 id="&#x6539;&#x8FDB;&#x7248;_1"><a name="&#x6539;&#x8FDB;&#x7248;_1"
                          class="anchor-navigation-ex-anchor" href="#&#x6539;&#x8FDB;&#x7248;_1"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="&#x6539;&#x8FDB;&#x7248;" class="plugin-anchor"
                          href="#&#x6539;&#x8FDB;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x6539;&#x8FDB;&#x7248;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">selectSort</span> (<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-comment">// &#x6392;&#x51FA; lenth - 1 &#x4E2A;&#x6700;&#x5C0F;&#x503C;&#x5373;&#x53EF;</span>
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len_i = arr.length - <span class="hljs-number">1</span>; i &lt; len_i; i++) {
    <span class="hljs-keyword">let</span> index = i
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = i + <span class="hljs-number">1</span>, len_j = arr.length; j &lt; len_j; j++) {
      <span class="hljs-keyword">if</span> (arr[index] &gt; arr[j]) {
        index = j
      }
    }
    <span class="hljs-comment">// &#x5224;&#x65AD;&#x6700;&#x5C0F;&#x7D22;&#x5F15;&#x662F;&#x5426;&#x6539;&#x53D8;</span>
    <span class="hljs-keyword">if</span> (index !== i) {
      [arr[i], arr[index]] = [arr[index], arr[i]]
    }
  }
}
</code></pre>
                  <h3 id="&#x2605;&#x2605;-&#x63D2;&#x5165;&#x6392;&#x5E8F;"><a
                      name="&#x2605;&#x2605;-&#x63D2;&#x5165;&#x6392;&#x5E8F;" class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;-&#x63D2;&#x5165;&#x6392;&#x5E8F;"><i class="fa fa-link"
                        aria-hidden="true"></i></a><a name="&#x2605;&#x2605;-&#x63D2;&#x5165;&#x6392;&#x5E8F;"
                      class="plugin-anchor" href="#&#x2605;&#x2605;-&#x63D2;&#x5165;&#x6392;&#x5E8F;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-3">&#x2605;&#x2605; &#x63D2;&#x5165;&#x6392;&#x5E8F;</p>
                  </h3>
                  <blockquote>
                    <p>&#x9ED8;&#x8BA4;&#x4E00;&#x4E2A;&#x5DF2;&#x6392;&#x597D;&#x5E8F;&#x7684;&#x6570;&#x7EC4;
                      &#x9012;&#x589E;&#x7684;&#x5F80;&#x8FD9;&#x4E2A;&#x6570;&#x7EC4;&#x5185;&#x63D2;&#x5165;&#x5143;&#x7D20;
                    </p>
                  </blockquote>
                  <ul>
                    <li>
                      <h4 id="&#x7248;&#x672C;&#x4E00;"><a name="&#x7248;&#x672C;&#x4E00;"
                          class="anchor-navigation-ex-anchor" href="#&#x7248;&#x672C;&#x4E00;"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="&#x7248;&#x672C;&#x4E00;" class="plugin-anchor"
                          href="#&#x7248;&#x672C;&#x4E00;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x7248;&#x672C;&#x4E00;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">insertSort</span> (<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-comment">// &#x5C06;&#x8981;&#x63D2;&#x5165;&#x7684;&#x7D22;&#x5F15;</span>
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">1</span>, len_i = arr.length; i &lt; len_i; i++) {
    <span class="hljs-keyword">let</span> cur = i
    <span class="hljs-comment">// &#x63D2;&#x5165;&#x5230;&#x5DF2;&#x7ECF;&#x6392;&#x597D;&#x5E8F;&#x7684;&#x5E8F;&#x5217;&#x4E2D;</span>
    <span class="hljs-keyword">while</span> (cur &gt; <span class="hljs-number">0</span> &amp;&amp; arr[cur] &lt; arr[cur - <span class="hljs-number">1</span>]) {
      [arr[cur], arr[cur - <span class="hljs-number">1</span>]] = [arr[cur - <span class="hljs-number">1</span>], arr[cur]]
      cur--
    }
  }
}
</code></pre>
                  <ul>
                    <li>
                      <h4 id="&#x7248;&#x672C;&#x4E8C;"><a name="&#x7248;&#x672C;&#x4E8C;"
                          class="anchor-navigation-ex-anchor" href="#&#x7248;&#x672C;&#x4E8C;"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="&#x7248;&#x672C;&#x4E8C;" class="plugin-anchor"
                          href="#&#x7248;&#x672C;&#x4E8C;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x7248;&#x672C;&#x4E8C;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">insertSort</span> (<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-comment">// &#x5C06;&#x8981;&#x63D2;&#x5165;&#x7684;&#x7D22;&#x5F15;</span>
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">1</span>, len = arr.length; i &lt; len; i++) {
    <span class="hljs-keyword">let</span> tmp = arr[i]

    <span class="hljs-comment">// &#x63D2;&#x5165;&#x5230;&#x5DF2;&#x7ECF;&#x6392;&#x597D;&#x5E8F;&#x7684;&#x5E8F;&#x5217;&#x4E2D;</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = i - <span class="hljs-number">1</span>; j &gt;= <span class="hljs-number">0</span> &amp;&amp; arr[j] &gt; tmp; j--) {
      arr[j + <span class="hljs-number">1</span>] = arr[j]
    }
    arr[j + <span class="hljs-number">1</span>] = tmp
  }
}
</code></pre>
                  <h3 id="&#x2605;&#x2605;-&#x5E0C;&#x5C14;&#x6392;&#x5E8F;"><a
                      name="&#x2605;&#x2605;-&#x5E0C;&#x5C14;&#x6392;&#x5E8F;" class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;-&#x5E0C;&#x5C14;&#x6392;&#x5E8F;"><i class="fa fa-link"
                        aria-hidden="true"></i></a><a name="&#x2605;&#x2605;-&#x5E0C;&#x5C14;&#x6392;&#x5E8F;"
                      class="plugin-anchor" href="#&#x2605;&#x2605;-&#x5E0C;&#x5C14;&#x6392;&#x5E8F;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-4">&#x2605;&#x2605; &#x5E0C;&#x5C14;&#x6392;&#x5E8F;</p>
                  </h3>
                  <blockquote>
                    <p>&#x589E;&#x91CF;&#x5F0F;&#x7684;<strong><code>&#x63D2;&#x5165;&#x6392;&#x5E8F;</code></strong>
                      &#x6B63;&#x5E38;&#x7684;&#x63D2;&#x5165;&#x6392;&#x5E8F;&#x95F4;&#x9694;&#x4E3A;1
                      &#x5E0C;&#x5C14;&#x6392;&#x5E8F;&#x9ED8;&#x8BA4;&#x8BBE;&#x7F6E;&#x95F4;&#x9694;&#x5927;&#x4E8E;1
                      &#x7136;&#x540E;&#x9012;&#x51CF;&#x4E3A;1</p>
                  </blockquote>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">shellSort</span> (<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-keyword">let</span> len = arr.length
  <span class="hljs-keyword">let</span> step = <span class="hljs-number">1</span>
  <span class="hljs-keyword">let</span> dis = <span class="hljs-number">3</span>
  <span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x6700;&#x5927;&#x95F4;&#x9694;</span>
  <span class="hljs-keyword">while</span> (step &lt; len / dis) {
    step = step * dis + <span class="hljs-number">1</span>
  }

  <span class="hljs-comment">// &#x95F4;&#x9694;&#x9012;&#x51CF;</span>
  <span class="hljs-keyword">for</span> (; step &gt; <span class="hljs-number">0</span>; step = <span class="hljs-built_in">Math</span>.floor(step / dis)) {
    <span class="hljs-comment">// &#x5355;&#x4E2A;&#x95F4;&#x9694;&#x7684;&#x63D2;&#x5165;&#x6392;&#x5E8F;</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = step; i &lt; len; i++) {
      <span class="hljs-keyword">let</span> tmp = arr[i]
      <span class="hljs-keyword">let</span> j = i - step

      <span class="hljs-keyword">while</span> (j &gt;= <span class="hljs-number">0</span> &amp;&amp; arr[j] &gt; tmp) {
        arr[j + step] = arr[j]
        j -= step
      }
      arr[j + step] = tmp
    }
  }
}
</code></pre>
                  <h3 id="&#x2605;&#x2605;-&#x5F52;&#x5E76;&#x6392;&#x5E8F;"><a
                      name="&#x2605;&#x2605;-&#x5F52;&#x5E76;&#x6392;&#x5E8F;" class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;-&#x5F52;&#x5E76;&#x6392;&#x5E8F;"><i class="fa fa-link"
                        aria-hidden="true"></i></a><a name="&#x2605;&#x2605;-&#x5F52;&#x5E76;&#x6392;&#x5E8F;"
                      class="plugin-anchor" href="#&#x2605;&#x2605;-&#x5F52;&#x5E76;&#x6392;&#x5E8F;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-5">&#x2605;&#x2605; &#x5F52;&#x5E76;&#x6392;&#x5E8F;</p>
                  </h3>
                  <blockquote>
                    <p>
                      &#x6392;&#x5E8F;&#x4E4B;&#x524D;&#x5C06;&#x6570;&#x7EC4;&#x62C6;&#x5206;&#x4E3A;&#x4E24;&#x90E8;&#x5206;&#x6392;&#x5E8F;
                      &#x7136;&#x540E;&#x5C06;&#x6392;&#x597D;&#x5E8F;&#x7684;&#x4E24;&#x4E2A;&#x90E8;&#x5206;&#x8FDB;&#x884C;&#x5408;&#x5E76;&#x6392;&#x5E8F;
                    </p>
                  </blockquote>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mergeSort</span> (<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-keyword">if</span> (arr.length &lt;= <span class="hljs-number">1</span>) <span class="hljs-keyword">return</span> ;
  <span class="hljs-keyword">let</span> left = <span class="hljs-number">0</span>,
  <span class="hljs-keyword">let</span> right = arr.length - <span class="hljs-number">1</span>,
  <span class="hljs-keyword">let</span> mid = <span class="hljs-built_in">parseInt</span>((left + right) * <span class="hljs-number">0.5</span>)

  sort(arr, left, mid)
  sort(arr, mid + <span class="hljs-number">1</span>, right)
  merge(arr, left, mid, right)
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sort</span> (<span class="hljs-params">arr, left, right</span>) </span>{
  <span class="hljs-comment">// &#x5206;&#x89E3;&#x4E3A;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</span>
  <span class="hljs-keyword">if</span> (left &gt;= right) <span class="hljs-keyword">return</span> ;
  <span class="hljs-keyword">let</span> mid = <span class="hljs-built_in">parseInt</span>((left + right) * <span class="hljs-number">0.5</span>)

  sort(arr, left, mid)
  sort(arr, mid + <span class="hljs-number">1</span>, right)
  merge(arr, left, mid, right)
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">merge</span> (<span class="hljs-params">arr, left, mid, right</span>) </span>{
  <span class="hljs-comment">// &#x5408;&#x5E76;&#x7684;[left, mid] [mid + 1, right] &#x90E8;&#x5206; &#x90FD;&#x5DF2;&#x7ECF;&#x6392;&#x597D;&#x5E8F;</span>
  <span class="hljs-keyword">let</span> i = left
  <span class="hljs-keyword">let</span> j = mid + <span class="hljs-number">1</span>
  <span class="hljs-keyword">let</span> tmp = []

  <span class="hljs-comment">// &#x4F9D;&#x6B21;&#x63D2;&#x5165;&#x8FDE;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x5143;&#x7D20;</span>
  <span class="hljs-keyword">while</span> (i &lt;= mid &amp;&amp; j &lt;= right) {
    <span class="hljs-comment">// &#x8FD9;&#x91CC;&#x7684;&#x7B49;&#x4E8E;&#x4FDD;&#x8BC1;&#x4E86;&#x6392;&#x5E8F;&#x7B97;&#x6CD5;&#x7A33;&#x5B9A;&#x6027;(&#x5373;&#x4E24;&#x4E2A;&#x76F8;&#x7B49;&#x7684;&#x6570;&#x6392;&#x5E8F;&#x540E;&#x7684;&#x4F4D;&#x7F6E;&#x4E0D;&#x4F1A;&#x6539;&#x53D8;)</span>
    <span class="hljs-keyword">if</span> (arr[i] &lt;= arr[j]) {
      tmp.push(arr[i])
      i++
    } <span class="hljs-keyword">else</span> {
      tmp.push(arr[j++])
    }
  }
  <span class="hljs-comment">// &#x5904;&#x7406;&#x5269;&#x4F59;&#x7684;&#x5DE6;&#x8FB9;/&#x53F3;&#x8FB9;&#x5143;&#x7D20;</span>
  <span class="hljs-keyword">while</span> (i &lt;= mid) tmp.push(arr[i++])
  <span class="hljs-keyword">while</span> (j &lt;= right) tmp.push(arr[j++])
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len = tmp.length; i &lt; len; i++) {
    arr[left + i] = tmp[i]
  }
}
</code></pre>
                  <h3 id="&#x2605;&#x2605;&#x2605;-&#x5FEB;&#x901F;&#x6392;&#x5E8F;"><a
                      name="&#x2605;&#x2605;&#x2605;-&#x5FEB;&#x901F;&#x6392;&#x5E8F;"
                      class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;&#x2605;-&#x5FEB;&#x901F;&#x6392;&#x5E8F;"><i class="fa fa-link"
                        aria-hidden="true"></i></a><a name="&#x2605;&#x2605;&#x2605;-&#x5FEB;&#x901F;&#x6392;&#x5E8F;"
                      class="plugin-anchor" href="#&#x2605;&#x2605;&#x2605;-&#x5FEB;&#x901F;&#x6392;&#x5E8F;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-6">&#x2605;&#x2605;&#x2605; &#x5FEB;&#x901F;&#x6392;&#x5E8F;</p>
                  </h3>
                  <blockquote>
                    <p>
                      &#x6392;&#x5E8F;&#x4E4B;&#x524D;&#x5C06;&#x6570;&#x7EC4;&#x62C6;&#x6309;&#x7167;&#x6307;&#x5B9A;&#x6307;&#x5B9A;&#x57FA;&#x70B9;&#x62C6;&#x5206;&#x4E3A;&#x4E24;&#x90E8;&#x5206;
                      &#x4E00;&#x90E8;&#x5206;&#x5C0F;&#x4E8E;&#x7B49;&#x4E8E;&#x57FA;&#x70B9;
                      &#x4E00;&#x90E8;&#x5206;&#x5927;&#x4E8E;&#x57FA;&#x70B9;</p>
                  </blockquote>
                  <ul>
                    <li>
                      <h4 id="&#x7248;&#x672C;&#x4E00;_1"><a name="&#x7248;&#x672C;&#x4E00;_1"
                          class="anchor-navigation-ex-anchor" href="#&#x7248;&#x672C;&#x4E00;_1"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="&#x7248;&#x672C;&#x4E00;" class="plugin-anchor"
                          href="#&#x7248;&#x672C;&#x4E00;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x7248;&#x672C;&#x4E00;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">quickSort</span> (<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-keyword">if</span> (arr.length &lt;= <span class="hljs-number">1</span>) <span class="hljs-keyword">return</span> ;
  <span class="hljs-keyword">let</span> left = <span class="hljs-number">0</span>
  <span class="hljs-keyword">let</span> right = arr.length - <span class="hljs-number">1</span>

  sort(arr, left, right)
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sort</span> (<span class="hljs-params">arr, left, right</span>) </span>{
  <span class="hljs-keyword">if</span> (left &gt;= right) <span class="hljs-keyword">return</span> ;
  <span class="hljs-keyword">let</span> baseValue = arr[left]
  <span class="hljs-keyword">let</span> start = left
  <span class="hljs-keyword">let</span> end = right
  <span class="hljs-keyword">while</span> (start &lt; end) {
    <span class="hljs-comment">// &#x627E;&#x5230;&#x53F3;&#x8FB9;&#x5C0F;&#x4E8E;&#x57FA;&#x70B9;&#x7684;&#x503C;&#x7684;&#x7D22;&#x5F15;</span>
    <span class="hljs-keyword">while</span> (start &lt; end &amp;&amp; arr[end] &gt;= baseValue) end--
    <span class="hljs-comment">// &#x627E;&#x5230;&#x5DE6;&#x8FB9;&#x5927;&#x4E8E;&#x57FA;&#x70B9;&#x7684;&#x503C;&#x7684;&#x7D22;&#x5F15;</span>
    <span class="hljs-keyword">while</span> (start &lt; end &amp;&amp; arr[start] &lt;= baseValue) start++
    <span class="hljs-keyword">if</span> (start &lt; end) {
      [arr[start], arr[end]] = [arr[end], arr[start]]
    }
  }
  [arr[left], arr[start]] = [arr[start], arr[left]]
  sort(arr, left, start - <span class="hljs-number">1</span>)
  sort(arr, start + <span class="hljs-number">1</span>, right)
}
</code></pre>
                  <ul>
                    <li>
                      <h4 id="&#x7248;&#x672C;&#x4E8C;_1"><a name="&#x7248;&#x672C;&#x4E8C;_1"
                          class="anchor-navigation-ex-anchor" href="#&#x7248;&#x672C;&#x4E8C;_1"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="&#x7248;&#x672C;&#x4E8C;" class="plugin-anchor"
                          href="#&#x7248;&#x672C;&#x4E8C;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x7248;&#x672C;&#x4E8C;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">quickSort</span>(<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-keyword">if</span> (arr.length &lt;= <span class="hljs-number">1</span>) <span class="hljs-keyword">return</span> ;
  <span class="hljs-keyword">let</span> left = <span class="hljs-number">0</span>
  <span class="hljs-keyword">let</span> right = arr.length - <span class="hljs-number">1</span>

  sort(arr, left, right)
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sort</span> (<span class="hljs-params">arr, left, right</span>) </span>{
  <span class="hljs-keyword">if</span> (left &gt;= right) <span class="hljs-keyword">return</span> ;
  <span class="hljs-keyword">let</span> baseValue = arr[left]
  <span class="hljs-keyword">let</span> leftArr = []
  <span class="hljs-keyword">let</span> rightArr = []

  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = left; i &lt;= right; i++) {
    <span class="hljs-keyword">if</span> (arr[i] &lt;= baseValue) {
      leftArr.push(arr[i])
    } <span class="hljs-keyword">else</span> {
      rightArr.push(arr[i])
    }
  }
  <span class="hljs-keyword">let</span> mid = left + leftArr.length - <span class="hljs-number">1</span>
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len = leftArr.length; i &lt; len; i++) {
    arr[left + i] = leftArr[i]
  }
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len = rightArr.length; i &lt; len; i++) {
    arr[mid + i + <span class="hljs-number">1</span>] = rightArr[i]
  }
  [arr[left], arr[mid]] = [arr[mid], arr[left]]
  sort(arr, left, mid - <span class="hljs-number">1</span>)
  sort(arr, mid + <span class="hljs-number">1</span>, right)
}
</code></pre>
                  <h3 id="&#x2605;&#x2605;-&#x5806;&#x6392;&#x5E8F;"><a name="&#x2605;&#x2605;-&#x5806;&#x6392;&#x5E8F;"
                      class="anchor-navigation-ex-anchor" href="#&#x2605;&#x2605;-&#x5806;&#x6392;&#x5E8F;"><i
                        class="fa fa-link" aria-hidden="true"></i></a><a
                      name="&#x2605;&#x2605;-&#x5806;&#x6392;&#x5E8F;" class="plugin-anchor"
                      href="#&#x2605;&#x2605;-&#x5806;&#x6392;&#x5E8F;"><i class="fa fa-link"
                        aria-hidden="true"></i></a>
                    <p id="algorithm-7">&#x2605;&#x2605; &#x5806;&#x6392;&#x5E8F;</p>
                  </h3>
                  <blockquote>
                    <p>&#x5C06;&#x6570;&#x7EC4;&#x770B;&#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x5806;&#x7ED3;&#x6784;
                      &#x5176;&#x4E2D; index = 0 &#x4E3A;&#x6839;&#x8282;&#x70B9; </p>
                    <p>index &#x6307;&#x5411;&#x7684;&#x8282;&#x70B9;&#x7684;&#x5B50;&#x8282;&#x70B9;&#x6709; 2*index +
                      1 2*index + 2 0 -&gt; 1, 2 1 -&gt; 3, 4 2 -&gt; 5, 6...</p>
                    <p>
                      &#x5B9E;&#x9645;&#x7684;&#x64CD;&#x4F5C;&#x5C31;&#x662F;&#x5BF9;&#x8FD9;&#x4E2A;&#x5806;&#x8FDB;&#x884C;&#x8C03;&#x6574;
                      &#x5806;&#x8FD9;&#x4E2A;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x53EF;&#x4EE5;&#x53BB;&#x4E86;&#x89E3;&#x4E00;&#x4E0B;
                    </p>
                    <p>&#x53C2;&#x8003; <a href="https://www.cnblogs.com/chengxiao/p/6129630.html"
                        target="_blank">https://www.cnblogs.com/chengxiao/p/6129630.html</a></p>
                  </blockquote>
                  <pre><code class="lang-javascript"><span class="hljs-comment">// &#x5806;&#x6392;&#x5E8F;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">heapSort</span> (<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-comment">// &#x4ECE;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x975E;&#x53F6;&#x5B50;&#x8282;&#x70B9;&#x5F00;&#x59CB;  &#x6784;&#x5EFA;&#x5927;&#x9876;&#x5806;   &#x5373;&#x6BCF;&#x6B21;&#x627E;&#x51FA;&#x6700;&#x5927;&#x7684;&#x4E00;&#x4E2A;&#x6570;</span>
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-built_in">Math</span>.floor(arr.length * <span class="hljs-number">0.5</span> - <span class="hljs-number">1</span>); i &gt;= <span class="hljs-number">0</span>; i--) {
    adjustHeap(arr, i, arr.length)
  }
  <span class="hljs-comment">// &#x5C06;&#x6700;&#x5927;&#x7684;&#x4E00;&#x4E2A;&#x8282;&#x70B9;&#x653E;&#x5728;&#x672B;&#x5C3E; &#x7B49;&#x4E8E;&#x6392;&#x597D;&#x5E8F;&#x4E86; &#x5728;&#x5BF9;&#x5269;&#x4E0B;&#x7684;&#x5143;&#x7D20;&#x6784;&#x5EFA;&#x5927;&#x9876;&#x5806;</span>
  <span class="hljs-keyword">for</span> (j = arr.length - <span class="hljs-number">1</span>; j &gt; <span class="hljs-number">0</span>; j--) {
    [arr[<span class="hljs-number">0</span>], arr[j]] = [arr[j], arr[<span class="hljs-number">0</span>]]
    <span class="hljs-comment">// &#x5927;&#x90E8;&#x5206;&#x90FD;&#x4E0D;&#x9700;&#x8981;&#x8C03;&#x6574;&#x4E86; &#x6240;&#x4EE5;&#x76F4;&#x63A5;&#x4ECE;&#x6839;&#x8282;&#x70B9;&#x5F00;&#x59CB;</span>
    adjustHeap(arr, <span class="hljs-number">0</span>, j)
  }
}
<span class="hljs-comment">// &#x8C03;&#x6574;&#x5806;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">adjustHeap</span> (<span class="hljs-params">arr, i, len</span>) </span>{
  <span class="hljs-comment">// k = 2 * k + 1 &#x662F;&#x5728;&#x4EA4;&#x6362;&#x4E24;&#x4E2A;&#x8282;&#x70B9;&#x65F6;&#x4F1A;&#x5BFC;&#x81F4;&#x539F;&#x6765;&#x7684;&#x5806;&#x7ED3;&#x6784;&#x6DF7;&#x4E71;&#xFF0C;&#x9700;&#x8981;&#x91CD;&#x65B0;&#x8C03;&#x6574;&#x5B50;&#x8282;&#x70B9;</span>
  <span class="hljs-keyword">let</span> cnt = <span class="hljs-number">0</span>
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> k = <span class="hljs-number">2</span> * i + <span class="hljs-number">1</span>; k &lt; len; k = <span class="hljs-number">2</span> * k + <span class="hljs-number">1</span>) {
    <span class="hljs-comment">// &#x627E;&#x51FA;&#x5DE6;&#x5B50;&#x8282;&#x70B9;&#x4E0E;&#x53F3;&#x5B50;&#x8282;&#x70B9;&#x4E2D;&#x6700;&#x5927;&#x7684;&#x8282;&#x70B9;</span>
    <span class="hljs-keyword">if</span> (k + <span class="hljs-number">1</span> &lt; len &amp;&amp; arr[k] &lt; arr[k + <span class="hljs-number">1</span>]) k++
    <span class="hljs-comment">// &#x5224;&#x65AD;&#x662F;&#x5426;&#x4E0E;&#x5B50;&#x8282;&#x70B9;&#x8FDB;&#x884C;&#x4EA4;&#x6362;</span>
    <span class="hljs-keyword">if</span> (arr[k] &gt; arr[i]) {
      [arr[k], arr[i]] = [arr[i], arr[k]]
      <span class="hljs-comment">// &#x4EA4;&#x6362;&#x5B8C;&#x6210;&#x540E;&#x8981;&#x5BF9;&#x4E0B;&#x4E00;&#x7EA7;&#x8282;&#x70B9;&#x8FDB;&#x884C;&#x91CD;&#x65B0;&#x8C03;&#x6574;</span>
      i = k
    } <span class="hljs-keyword">else</span> {
      <span class="hljs-keyword">break</span> ;
    }
  }
}
</code></pre>
                  <h3 id="&#x2605;&#x2605;&#x2605;-&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;"><a
                      name="&#x2605;&#x2605;&#x2605;-&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;"
                      class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;&#x2605;-&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;"><i
                        class="fa fa-link" aria-hidden="true"></i></a><a
                      name="&#x2605;&#x2605;&#x2605;-&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;"
                      class="plugin-anchor"
                      href="#&#x2605;&#x2605;&#x2605;-&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-8">&#x2605;&#x2605;&#x2605; &#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217;</p>
                  </h3>
                  <blockquote>
                    <p>&#x6590;&#x6CE2;&#x90A3;&#x5951;&#x6570;&#x5217; 0 1 1 2 3 5 8 13 ... &#x7B2C; n
                      &#x9879;&#x4E3A;&#x7B2C; n-1 &#x4E0E; &#x7B2C; n-2 &#x9879;&#x7684;&#x548C;
                      &#x9996;&#x9879;&#x4E3A;0 &#x7B2C;&#x4E8C;&#x9879;&#x4E3A;1</p>
                  </blockquote>
                  <ul>
                    <li>
                      <h4 id="&#x4F7F;&#x7528;&#x5FAA;&#x73AF;"><a name="&#x4F7F;&#x7528;&#x5FAA;&#x73AF;"
                          class="anchor-navigation-ex-anchor" href="#&#x4F7F;&#x7528;&#x5FAA;&#x73AF;"><i
                            class="fa fa-link" aria-hidden="true"></i></a><a name="&#x4F7F;&#x7528;&#x5FAA;&#x73AF;"
                          class="plugin-anchor" href="#&#x4F7F;&#x7528;&#x5FAA;&#x73AF;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x4F7F;&#x7528;&#x5FAA;&#x73AF;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fibonacci</span> (<span class="hljs-params">n</span>) </span>{
  <span class="hljs-keyword">if</span> (n &lt;= <span class="hljs-number">2</span>) <span class="hljs-keyword">return</span> n - <span class="hljs-number">1</span>
  <span class="hljs-keyword">let</span> n1 = <span class="hljs-number">0</span>, n2 = <span class="hljs-number">1</span>

  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">2</span>; i &lt; n; i++) {
    [n1, n2] = [n2, n1 + n2]
  }
  <span class="hljs-keyword">return</span> n2
}
</code></pre>
                  <ul>
                    <li>
                      <h4 id="&#x4F7F;&#x7528;&#x9012;&#x5F52;"><a name="&#x4F7F;&#x7528;&#x9012;&#x5F52;"
                          class="anchor-navigation-ex-anchor" href="#&#x4F7F;&#x7528;&#x9012;&#x5F52;"><i
                            class="fa fa-link" aria-hidden="true"></i></a><a name="&#x4F7F;&#x7528;&#x9012;&#x5F52;"
                          class="plugin-anchor" href="#&#x4F7F;&#x7528;&#x9012;&#x5F52;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x4F7F;&#x7528;&#x9012;&#x5F52;</h4>
                    </li>
                  </ul>
                  <blockquote>
                    <p>&#x6D88;&#x8017;&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x8F83;&#x5927;</p>
                  </blockquote>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fibonacci</span> (<span class="hljs-params">n</span>) </span>{
  <span class="hljs-keyword">return</span> n &lt;= <span class="hljs-number">2</span> ? n - <span class="hljs-number">1</span> : Fibonacci(n - <span class="hljs-number">1</span>) + Fibonacci(n - <span class="hljs-number">2</span>)
}

<span class="hljs-comment">// &#x8BBE;&#x7F6E;&#x7F13;&#x5B58;</span>
<span class="hljs-keyword">let</span> cache = {}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fibonacci</span> (<span class="hljs-params">n</span>) </span>{
  <span class="hljs-keyword">if</span> (n &lt;= <span class="hljs-number">0</span>) <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>
  <span class="hljs-keyword">if</span> (n &lt;= <span class="hljs-number">2</span>) <span class="hljs-keyword">return</span> n - <span class="hljs-number">1</span>
  <span class="hljs-keyword">if</span> (cache[n]) <span class="hljs-keyword">return</span> cache[n] 

  <span class="hljs-keyword">return</span> cache[n] = Fibonacci(n - <span class="hljs-number">1</span>) + Fibonacci(n - <span class="hljs-number">2</span>)
}
</code></pre>
                  <h3 id="&#x2605;&#x2605;-&#x6C49;&#x8BFA;&#x5854;&#x95EE;&#x9898;"><a
                      name="&#x2605;&#x2605;-&#x6C49;&#x8BFA;&#x5854;&#x95EE;&#x9898;"
                      class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;-&#x6C49;&#x8BFA;&#x5854;&#x95EE;&#x9898;"><i class="fa fa-link"
                        aria-hidden="true"></i></a><a name="&#x2605;&#x2605;-&#x6C49;&#x8BFA;&#x5854;&#x95EE;&#x9898;"
                      class="plugin-anchor" href="#&#x2605;&#x2605;-&#x6C49;&#x8BFA;&#x5854;&#x95EE;&#x9898;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-9">&#x2605;&#x2605; &#x6C49;&#x8BFA;&#x5854;&#x95EE;&#x9898;</p>
                  </h3>
                  <blockquote>
                    <p>&#x6C49;&#x8BFA;&#x5854;&#x89C4;&#x5219;&#x53C2;&#x7167; <a
                        href="https://baike.baidu.com/item/%E6%B1%89%E8%AF%BA%E5%A1%94/3468295"
                        target="_blank">https://baike.baidu.com/item/%E6%B1%89%E8%AF%BA%E5%A1%94/3468295</a></p>
                  </blockquote>
                  <ul>
                    <li>
                      <h4 id="&#x9012;&#x5F52;&#x89E3;&#x51B3;"><a name="&#x9012;&#x5F52;&#x89E3;&#x51B3;"
                          class="anchor-navigation-ex-anchor" href="#&#x9012;&#x5F52;&#x89E3;&#x51B3;"><i
                            class="fa fa-link" aria-hidden="true"></i></a><a name="&#x9012;&#x5F52;&#x89E3;&#x51B3;"
                          class="plugin-anchor" href="#&#x9012;&#x5F52;&#x89E3;&#x51B3;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x9012;&#x5F52;&#x89E3;&#x51B3;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-comment">// &#x4E09;&#x6839;&#x67F1;&#x5B50;&#x5206;&#x522B;&#x4E3A; A B C  A &#x4E3A;&#x521D;&#x59CB;&#x4F4D;&#x7F6E;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">hanoi</span> (<span class="hljs-params">n, current = &apos;A&apos;, temp = &apos;B&apos;, target = &apos;C&apos;</span>) </span>{
  <span class="hljs-keyword">if</span> (n &lt;= <span class="hljs-number">0</span>) <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>
  <span class="hljs-keyword">let</span> sum = <span class="hljs-number">1</span>

  sum += hanoi(n - <span class="hljs-number">1</span>, current, target, temp)
  <span class="hljs-built_in">console</span>.log(current + <span class="hljs-string">&apos; ---&gt; &apos;</span> + target)
  sum += hanoi(n - <span class="hljs-number">1</span>, temp, target, current)
  <span class="hljs-keyword">return</span> sum
}
</code></pre>
                  <h3 id="&#x2605;&#x2605;-&#x5408;&#x5E76;&#x4E24;&#x4E2A;&#x6709;&#x5E8F;&#x6570;&#x7EC4;"><a
                      name="&#x2605;&#x2605;-&#x5408;&#x5E76;&#x4E24;&#x4E2A;&#x6709;&#x5E8F;&#x6570;&#x7EC4;"
                      class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;-&#x5408;&#x5E76;&#x4E24;&#x4E2A;&#x6709;&#x5E8F;&#x6570;&#x7EC4;"><i
                        class="fa fa-link" aria-hidden="true"></i></a><a
                      name="&#x2605;&#x2605;-&#x5408;&#x5E76;&#x4E24;&#x4E2A;&#x6709;&#x5E8F;&#x6570;&#x7EC4;"
                      class="plugin-anchor"
                      href="#&#x2605;&#x2605;-&#x5408;&#x5E76;&#x4E24;&#x4E2A;&#x6709;&#x5E8F;&#x6570;&#x7EC4;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-10">&#x2605;&#x2605;
                      &#x5408;&#x5E76;&#x4E24;&#x4E2A;&#x6709;&#x5E8F;&#x6570;&#x7EC4;</p>
                  </h3>
                  <blockquote>
                    <p>&#x76F4;&#x63A5;&#x53C2;&#x7167;&#x5F52;&#x5E76;&#x6392;&#x5E8F;&#x7684;&#x5408;&#x5E76;
                      merge&#x65B9;&#x6CD5;</p>
                  </blockquote>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mergeArr</span> (<span class="hljs-params">arr1, arr2</span>) </span>{
  <span class="hljs-keyword">let</span> result = []
  <span class="hljs-comment">// p1 &#x4E0E; p2 &#x5206;&#x522B;&#x4E3A; arr1 &#x4E0E; arr2 &#x7684;&#x7D22;&#x5F15;</span>
  <span class="hljs-keyword">let</span> p1 = p2 = <span class="hljs-number">0</span>
  <span class="hljs-keyword">let</span> len1 = arr1.length
  <span class="hljs-keyword">let</span> len2 = arr2.length

  <span class="hljs-keyword">while</span> (p1 &lt; len1 &amp;&amp; p2 &lt; len2) {
    arr1[p1] &lt;= arr2[p2] ? result.push(arr1[p1++]) : result.push(arr2[p2++])
  }
  <span class="hljs-keyword">while</span> (p1 &lt; len1) result.push(arr1[p1++])
  <span class="hljs-keyword">while</span> (p2 &lt; len2) result.push(arr2[p2++])
  <span class="hljs-keyword">return</span> result
}
</code></pre>
                  <ul>
                    <li>
                      <h4 id="api&#x7248;"><a name="api&#x7248;" class="anchor-navigation-ex-anchor"
                          href="#api&#x7248;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="api&#x7248;"
                          class="plugin-anchor" href="#api&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>API&#x7248;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mergeArr</span> (<span class="hljs-params">arr1, arr2</span>) </span>{
  <span class="hljs-comment">// sort &#x81EA;&#x5B9A;&#x4E49;&#x6392;&#x5E8F;&#x89C4;&#x5219;</span>
  <span class="hljs-keyword">return</span> (arr1.concat(arr2)).sort((a, b) =&gt; a - b)
}
</code></pre>
                  <h3 id="&#x2605;&#x2605;-&#x6570;&#x7EC4;&#x4E2D;&#x91CD;&#x590D;&#x7684;&#x6570;&#x5B57;"><a
                      name="&#x2605;&#x2605;-&#x6570;&#x7EC4;&#x4E2D;&#x91CD;&#x590D;&#x7684;&#x6570;&#x5B57;"
                      class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;-&#x6570;&#x7EC4;&#x4E2D;&#x91CD;&#x590D;&#x7684;&#x6570;&#x5B57;"><i
                        class="fa fa-link" aria-hidden="true"></i></a><a
                      name="&#x2605;&#x2605;-&#x6570;&#x7EC4;&#x4E2D;&#x91CD;&#x590D;&#x7684;&#x6570;&#x5B57;"
                      class="plugin-anchor"
                      href="#&#x2605;&#x2605;-&#x6570;&#x7EC4;&#x4E2D;&#x91CD;&#x590D;&#x7684;&#x6570;&#x5B57;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-11">&#x2605;&#x2605;
                      &#x6570;&#x7EC4;&#x4E2D;&#x91CD;&#x590D;&#x7684;&#x6570;&#x5B57;</p>
                  </h3>
                  <blockquote>
                    <p>&#x6570;&#x7EC4;&#x53BB;&#x91CD; &#x53EF;&#x4EE5;&#x53C2;&#x8003; <a
                        href="https://segmentfault.com/a/1190000016418021"
                        target="_blank">https://segmentfault.com/a/1190000016418021</a></p>
                  </blockquote>
                  <ul>
                    <li>
                      <h4 id="&#x7B80;&#x6613;&#x7248;"><a name="&#x7B80;&#x6613;&#x7248;"
                          class="anchor-navigation-ex-anchor" href="#&#x7B80;&#x6613;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="&#x7B80;&#x6613;&#x7248;" class="plugin-anchor"
                          href="#&#x7B80;&#x6613;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x7B80;&#x6613;&#x7248;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">noRepeat</span> (<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-keyword">return</span> [...new <span class="hljs-built_in">Set</span>(arr)]
}
</code></pre>
                  <ul>
                    <li>
                      <h4 id="&#x5FAA;&#x73AF;&#x7248;"><a name="&#x5FAA;&#x73AF;&#x7248;"
                          class="anchor-navigation-ex-anchor" href="#&#x5FAA;&#x73AF;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="&#x5FAA;&#x73AF;&#x7248;" class="plugin-anchor"
                          href="#&#x5FAA;&#x73AF;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x5FAA;&#x73AF;&#x7248;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">noRepeat</span> (<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-keyword">let</span> result = []

  <span class="hljs-comment">// &#x7B2C; n+1 &#x4E2A;&#x4E0D;&#x91CD;&#x590D;&#x7684;&#x5143;&#x7D20;</span>
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len_i = arr.length; i &lt; len_i; i++) {
    <span class="hljs-keyword">let</span> isNoRepeat = <span class="hljs-literal">true</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>, len_j = result.length; j &lt; len_j; j++) {
      <span class="hljs-comment">// &#x82E5;&#x6570;&#x7EC4;&#x4E2D;&#x53EA;&#x6709;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x7528; === &#x5224;&#x65AD;</span>
      isNoRepeat = !isEqual(arr[i], result[j])
      <span class="hljs-keyword">if</span> (!isNoRepeat) <span class="hljs-keyword">break</span>;
    }
    <span class="hljs-keyword">if</span> (isNoRepeat) result.push(arr[i])
  }
  <span class="hljs-keyword">return</span> result;
}

<span class="hljs-comment">// &#x7528;&#x5230;&#x7684;&#x65B9;&#x6CD5;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">isEqual</span> (<span class="hljs-params">obj1, obj2</span>) </span>{
  <span class="hljs-comment">// &#x5224;&#x65AD;&#x7C7B;&#x578B;&#x662F;&#x5426;&#x76F8;&#x540C;</span>
  <span class="hljs-keyword">let</span> type = getType(obj1)
  <span class="hljs-keyword">if</span> (type !== getType(obj2)) <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
  <span class="hljs-comment">// &#x5224;&#x65AD;&#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x503C;</span>
  <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> obj1 !== <span class="hljs-string">&apos;object&apos;</span>) <span class="hljs-keyword">return</span> obj1 === obj2;
  <span class="hljs-comment">// &#x5224;&#x65AD;&#x5730;&#x5740;</span>
  <span class="hljs-keyword">if</span> (obj1 === obj2) <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;

  <span class="hljs-comment">// &#x5224;&#x65AD;&#x503C;&#x662F;&#x5426;&#x76F8;&#x540C;</span>
  <span class="hljs-keyword">switch</span> (type) {
    <span class="hljs-comment">// &#x5BF9;&#x8C61;</span>
    <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;[object Object]&apos;</span>:
      <span class="hljs-comment">// &#x53D6;&#x5F97;&#x53EF;&#x904D;&#x5386;&#x5C5E;&#x6027;</span>
      <span class="hljs-keyword">let</span> keys1 = <span class="hljs-built_in">Object</span>.keys(obj1)
      <span class="hljs-keyword">let</span> keys2 = <span class="hljs-built_in">Object</span>.keys(obj2)
      <span class="hljs-keyword">if</span> (keys1.length !== keys.length) <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>
      <span class="hljs-comment">// &#x957F;&#x5EA6;&#x76F8;&#x7B49;</span>
      <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len = keys1.length; i &lt; len; i++) {
        <span class="hljs-keyword">let</span> key = keys1[i]
        <span class="hljs-keyword">if</span> (!isEqual(obj1[key], obj2[key])) <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
      }
      <span class="hljs-keyword">break</span>;
    <span class="hljs-comment">// Map</span>
    <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;[object Map]&apos;</span>:
    <span class="hljs-comment">// Set</span>
    <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;[object Set]&apos;</span>:
      <span class="hljs-comment">// &#x8F6C;&#x4E3A;&#x6570;&#x7EC4;</span>
      obj1 = <span class="hljs-built_in">Array</span>.from(obj1)
      obj2 = <span class="hljs-built_in">Array</span>.from(obj2)
    <span class="hljs-comment">// &#x6570;&#x7EC4;</span>
    <span class="hljs-keyword">case</span> <span class="hljs-string">&apos;[object Array]&apos;</span>:
      <span class="hljs-keyword">if</span> (obj1.length !== obj2.length) <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
      <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len = obj1.length; i &lt; len; i++) {
        <span class="hljs-keyword">if</span> (!isEqual(obj1[i], obj2[i])) <span class="hljs-keyword">return</span> <span class="hljs-literal">false</span>;
      }
      <span class="hljs-keyword">break</span>;
    <span class="hljs-comment">// ...</span>
    <span class="hljs-keyword">default</span>: <span class="hljs-keyword">break</span>;
  }
  <span class="hljs-keyword">return</span> <span class="hljs-literal">true</span>;
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getType</span> (<span class="hljs-params">obj</span>) </span>{
  <span class="hljs-comment">// &#x53EF;&#x4EE5;&#x5224;&#x65AD;&#x6570;&#x7EC4; Map Set&#x6570;&#x636E;&#x7C7B;&#x578B;</span>
  <span class="hljs-keyword">return</span> <span class="hljs-built_in">Object</span>.prototype.toString.call(obj)
}
</code></pre>
                  <ul>
                    <li>
                      <h4 id="&#x6807;&#x8BB0;&#x7248;"><a name="&#x6807;&#x8BB0;&#x7248;"
                          class="anchor-navigation-ex-anchor" href="#&#x6807;&#x8BB0;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="&#x6807;&#x8BB0;&#x7248;" class="plugin-anchor"
                          href="#&#x6807;&#x8BB0;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x6807;&#x8BB0;&#x7248;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">noRepeat</span> (<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-keyword">let</span> result = []
  <span class="hljs-comment">// &#x4F7F;&#x7528;&#x6807;&#x8BB0;  &#x4F7F;&#x7528; Map &#x53EF;&#x4EE5;&#x5224;&#x5B9A;&#x591A;&#x79CD;&#x6570;&#x636E;&#x7C7B;&#x578B;</span>
  <span class="hljs-comment">// &#x8FD9;&#x91CC;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; WeakMap &#x5F31;&#x5F15;&#x7528;  &#x5177;&#x4F53;&#x81EA;&#x5DF1;&#x53BB;&#x67E5;&#x8D44;&#x6599; js WeakMap&#x7C7B;&#x578B;</span>
  <span class="hljs-keyword">const</span> flag = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>()

  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len = arr.length; i &lt; len; i++) {
    <span class="hljs-comment">// &#x521D;&#x6B65;&#x5224;&#x5B9A;</span>
    <span class="hljs-keyword">if</span> (!flag.has(arr[i])) {
      <span class="hljs-keyword">let</span> isNoRepeat = <span class="hljs-literal">true</span>
      <span class="hljs-comment">// &#x57FA;&#x672C;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x76F4;&#x63A5;&#x63D2;&#x5165;</span>
      <span class="hljs-comment">// &#x5F15;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;</span>
      <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> arr[i] === <span class="hljs-string">&apos;object&apos;</span>) {
        <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>, len_j = result.length; j &lt; len_j; j++) {
          isNoRepeat = !isEqual(arr[i], result[j])
          <span class="hljs-keyword">if</span> (!isNoRepeat) <span class="hljs-keyword">break</span>;
        }
      }
      <span class="hljs-comment">// &#x6CA1;&#x6709;&#x91CD;&#x590D;</span>
      <span class="hljs-keyword">if</span> (isNoRepeat) {
        result.push(arr[i])
        flag.set(arr[i], <span class="hljs-literal">true</span>)
      }
    }
  }
  <span class="hljs-keyword">return</span> result
}
</code></pre>
                  <h3 id="&#x2605;&#x2605;-&#x4E24;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x4EA4;&#x96C6;"><a
                      name="&#x2605;&#x2605;-&#x4E24;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x4EA4;&#x96C6;"
                      class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;-&#x4E24;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x4EA4;&#x96C6;"><i
                        class="fa fa-link" aria-hidden="true"></i></a><a
                      name="&#x2605;&#x2605;-&#x4E24;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x4EA4;&#x96C6;"
                      class="plugin-anchor"
                      href="#&#x2605;&#x2605;-&#x4E24;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x4EA4;&#x96C6;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-12">&#x2605;&#x2605; &#x4E24;&#x4E2A;&#x6570;&#x7EC4;&#x7684;&#x4EA4;&#x96C6;</p>
                  </h3>
                  <blockquote>
                    <p>&#x4EA4;&#x96C6;&#x5C31;&#x662F;&#x76F8;&#x540C;&#x7684;&#x90E8;&#x5206;
                      &#x6CA1;&#x6709;&#x8BF4;&#x662F;&#x4E24;&#x4E2A;&#x96C6;&#x5408;
                      &#x6240;&#x4EE5;&#x6700;&#x7EC8;&#x7684;&#x4EA4;&#x96C6;&#x9700;&#x8981;&#x4FDD;&#x7559;&#x7D22;&#x5F15;&#x4E0D;&#x540C;&#x7684;&#x76F8;&#x540C;&#x7684;&#x5143;&#x7D20;
                    </p>
                  </blockquote>
                  <ul>
                    <li>
                      <h4 id="&#x57FA;&#x7840;&#x7248;_2"><a name="&#x57FA;&#x7840;&#x7248;_2"
                          class="anchor-navigation-ex-anchor" href="#&#x57FA;&#x7840;&#x7248;_2"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="&#x57FA;&#x7840;&#x7248;" class="plugin-anchor"
                          href="#&#x57FA;&#x7840;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x57FA;&#x7840;&#x7248;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">intersection</span> (<span class="hljs-params">arr1, arr2</span>) </span>{
  <span class="hljs-keyword">let</span> flag = {}
  <span class="hljs-keyword">let</span> result = []

  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len_i = arr1.length; i &lt; len_i; i++) {
    <span class="hljs-keyword">let</span> item = arr1[i]
    <span class="hljs-comment">// &#x641C;&#x7D22;&#x6709;&#x6CA1;&#x6709;    &#x4F7F;&#x7528; indexOf &#x6216; includes &#x4E5F;&#x6CA1;&#x95EE;&#x9898;</span>
    <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> j = <span class="hljs-number">0</span>, len_j = arr2.length; j &lt; len_j; j++) {
      <span class="hljs-comment">// &#x5224;&#x65AD;&#x76F8;&#x7B49;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#x4E4B;&#x524D;&#x5C01;&#x88C5;&#x7684; isEqual &#x65B9;&#x6CD5;</span>
      <span class="hljs-comment">// isEqual(arr1[i], arr2[i])</span>
      <span class="hljs-keyword">if</span> (item === arr2[j] &amp;&amp; !flag[j]) {
        result.push(item)
        flag[j] = <span class="hljs-literal">true</span>
        <span class="hljs-keyword">break</span>;
      }
    }
  }
  <span class="hljs-keyword">return</span> result
}
</code></pre>
                  <ul>
                    <li>
                      <h4 id="map&#x6807;&#x8BB0;&#x7248;"><a name="map&#x6807;&#x8BB0;&#x7248;"
                          class="anchor-navigation-ex-anchor" href="#map&#x6807;&#x8BB0;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="map&#x6807;&#x8BB0;&#x7248;" class="plugin-anchor"
                          href="#map&#x6807;&#x8BB0;&#x7248;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>Map&#x6807;&#x8BB0;&#x7248;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-comment">// &#x7F3A;&#x9677; &#x82E5;&#x5143;&#x7D20;&#x503C;&#x6709;&#x5F15;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x53EF;&#x80FD;&#x4F1A;&#x51FA;&#x9519;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">intersection</span> (<span class="hljs-params">arr1, arr2</span>) </span>{
  <span class="hljs-keyword">let</span> map = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>()
  <span class="hljs-keyword">let</span> result = []

  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len = arr1.length; i &lt; len; i++) {
    <span class="hljs-keyword">let</span> item = arr1[i]
    <span class="hljs-keyword">if</span> (map.has(item)) map.set(item, map.get(item) + <span class="hljs-number">1</span>)
    <span class="hljs-keyword">else</span> map.set(item, <span class="hljs-number">1</span>)
  }
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len = arr2.length; i &lt; len ;i++) {
    <span class="hljs-keyword">let</span> item = arr2[i]
    <span class="hljs-keyword">if</span> (map.has(item)) {
      result.push(item)
      map.set(item, map.get(item) - <span class="hljs-number">1</span>)
    }
  }
  <span class="hljs-keyword">return</span> result
}
</code></pre>
                  <ul>
                    <li>
                      <h4 id="api&#x7248;&#x672C;"><a name="api&#x7248;&#x672C;" class="anchor-navigation-ex-anchor"
                          href="#api&#x7248;&#x672C;"><i class="fa fa-link" aria-hidden="true"></i></a><a
                          name="api&#x7248;&#x672C;" class="plugin-anchor" href="#api&#x7248;&#x672C;"><i
                            class="fa fa-link" aria-hidden="true"></i></a>API&#x7248;&#x672C;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-comment">// &#x66F4;&#x9002;&#x5408;&#x6C42;&#x4E24;&#x4E2A;&#x96C6;&#x5408;&#x7684;&#x4EA4;&#x96C6;</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">intersection</span> (<span class="hljs-params">arr1, arr2</span>) </span>{
  <span class="hljs-comment">// return noRepeat(arr1).filter(v =&gt; arr2.includes(v))</span>
  <span class="hljs-keyword">return</span> [...new <span class="hljs-built_in">Set</span>(arr1)].filter(v =&gt; arr2.includes(v))
}
</code></pre>
                  <h3 id="&#x2605;&#x2605;-&#x65CB;&#x8F6C;&#x6570;&#x7EC4;"><a
                      name="&#x2605;&#x2605;-&#x65CB;&#x8F6C;&#x6570;&#x7EC4;" class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;-&#x65CB;&#x8F6C;&#x6570;&#x7EC4;"><i class="fa fa-link"
                        aria-hidden="true"></i></a><a name="&#x2605;&#x2605;-&#x65CB;&#x8F6C;&#x6570;&#x7EC4;"
                      class="plugin-anchor" href="#&#x2605;&#x2605;-&#x65CB;&#x8F6C;&#x6570;&#x7EC4;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-13">&#x2605;&#x2605; &#x65CB;&#x8F6C;&#x6570;&#x7EC4;</p>
                  </h3>
                  <blockquote>
                    <p>&#x5012;&#x5E8F;&#xFF1F; &#x6216;&#x8005;
                      &#x628A;&#x6570;&#x7EC4;&#x5F80;&#x53F3;&#x65CB;&#x8F6C;k&#x6B65;&#xFF0C;&#x8981;&#x6C42;&#x4E0D;&#x8FD4;&#x56DE;&#x65B0;&#x7684;&#x6570;&#x7EC4;&#xFF0C;&#x76F4;&#x63A5;&#x6539;&#x53D8;&#x539F;&#x6570;&#x7EC4;&#xFF1F;
                    </p>
                  </blockquote>
                  <ul>
                    <li>
                      <h4 id="&#x5012;&#x5E8F;"><a name="&#x5012;&#x5E8F;" class="anchor-navigation-ex-anchor"
                          href="#&#x5012;&#x5E8F;"><i class="fa fa-link" aria-hidden="true"></i></a><a
                          name="&#x5012;&#x5E8F;" class="plugin-anchor" href="#&#x5012;&#x5E8F;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x5012;&#x5E8F;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">reverse</span> (<span class="hljs-params">arr</span>) </span>{
  <span class="hljs-keyword">let</span> len = arr.length

  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, mid = <span class="hljs-built_in">parseInt</span>(len * <span class="hljs-number">0.5</span>); i &lt; mid; i++) {
    [arr[i], arr[len - i - <span class="hljs-number">1</span>]] = [arr[len - i - <span class="hljs-number">1</span>], arr[i]]
  }
  <span class="hljs-keyword">return</span> arr
}
</code></pre>
                  <ul>
                    <li>
                      <h4 id="&#x65CB;&#x8F6C;k&#x6B65;"><a name="&#x65CB;&#x8F6C;k&#x6B65;"
                          class="anchor-navigation-ex-anchor" href="#&#x65CB;&#x8F6C;k&#x6B65;"><i class="fa fa-link"
                            aria-hidden="true"></i></a><a name="&#x65CB;&#x8F6C;k&#x6B65;" class="plugin-anchor"
                          href="#&#x65CB;&#x8F6C;k&#x6B65;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x65CB;&#x8F6C;k&#x6B65;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">rotateArr</span> (<span class="hljs-params">arr, k</span>) </span>{
  <span class="hljs-keyword">let</span> len = arr.length
  <span class="hljs-keyword">let</span> tmp = [...arr]

  <span class="hljs-keyword">if</span> (k &lt; <span class="hljs-number">0</span>) k = (k % len) + len
  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &lt; len; i++) {
    <span class="hljs-keyword">let</span> index = (i + k) % len
    arr[index] = tmp[i]
  }
  <span class="hljs-keyword">return</span> arr
}
</code></pre>
                  <h3 id="&#x2605;&#x2605;-&#x4E24;&#x6570;&#x4E4B;&#x548C;"><a
                      name="&#x2605;&#x2605;-&#x4E24;&#x6570;&#x4E4B;&#x548C;" class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;-&#x4E24;&#x6570;&#x4E4B;&#x548C;"><i class="fa fa-link"
                        aria-hidden="true"></i></a><a name="&#x2605;&#x2605;-&#x4E24;&#x6570;&#x4E4B;&#x548C;"
                      class="plugin-anchor" href="#&#x2605;&#x2605;-&#x4E24;&#x6570;&#x4E4B;&#x548C;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-14">&#x2605;&#x2605; &#x4E24;&#x6570;&#x4E4B;&#x548C;</p>
                  </h3>
                  <blockquote>
                    <p>&#x7ED9;&#x5B9A;&#x4E00;&#x4E2A;&#x6574;&#x6570;&#x6570;&#x7EC4;<code>nums</code>
                      &#x548C;&#x4E00;&#x4E2A;&#x76EE;&#x6807;&#x503C;<code>target</code>&#xFF0C;&#x8BF7;&#x4F60;&#x5728;&#x8BE5;&#x6570;&#x7EC4;&#x4E2D;&#x627E;&#x51FA;&#x548C;&#x4E3A;&#x76EE;&#x6807;&#x503C;&#x7684;&#x90A3;<strong>&#x4E24;&#x4E2A;</strong>&#x6574;&#x6570;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x4ED6;&#x4EEC;&#x7684;&#x6570;&#x7EC4;&#x4E0B;&#x6807;&#x3002;
                    </p>
                    <p>
                      &#x4F60;&#x53EF;&#x4EE5;&#x5047;&#x8BBE;&#x6BCF;&#x79CD;&#x8F93;&#x5165;&#x53EA;&#x4F1A;&#x5BF9;&#x5E94;&#x4E00;&#x4E2A;&#x7B54;&#x6848;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x4F60;&#x4E0D;&#x80FD;&#x91CD;&#x590D;&#x5229;&#x7528;&#x8FD9;&#x4E2A;&#x6570;&#x7EC4;&#x4E2D;&#x540C;&#x6837;&#x7684;&#x5143;&#x7D20;&#x3002;
                    </p>
                    <p>&#x793A;&#x4F8B; nums = [2, 7, 11, 15] target = 9 &#x5219;&#x7ED3;&#x679C;&#x8FD4;&#x56DE; [0, 1]
                      &#x5373;&#x662F;2 &#x548C; 7&#x7684;&#x4E0B;&#x6807;</p>
                  </blockquote>
                  <pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">twoSum</span> (<span class="hljs-params">arr, target</span>) </span>{
  <span class="hljs-keyword">let</span> map = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>()

  <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, len = arr.length; i &lt; len; i++) {
    <span class="hljs-keyword">let</span> diff = target - arr[i]
    <span class="hljs-keyword">if</span> (map.has(diff)) {
      <span class="hljs-keyword">return</span> [map.get(diff), i]
    }
    map.set(arr[i], i)
  }
  <span class="hljs-keyword">return</span> <span class="hljs-string">&apos;not found&apos;</span>
}
</code></pre>
                  <h3 id="&#x2605;&#x2605;-&#x722C;&#x53F0;&#x9636;&#x7684;&#x5B9E;&#x73B0;&#x601D;&#x8DEF;"><a
                      name="&#x2605;&#x2605;-&#x722C;&#x53F0;&#x9636;&#x7684;&#x5B9E;&#x73B0;&#x601D;&#x8DEF;"
                      class="anchor-navigation-ex-anchor"
                      href="#&#x2605;&#x2605;-&#x722C;&#x53F0;&#x9636;&#x7684;&#x5B9E;&#x73B0;&#x601D;&#x8DEF;"><i
                        class="fa fa-link" aria-hidden="true"></i></a><a
                      name="&#x2605;&#x2605;-&#x722C;&#x53F0;&#x9636;&#x7684;&#x5B9E;&#x73B0;&#x601D;&#x8DEF;"
                      class="plugin-anchor"
                      href="#&#x2605;&#x2605;-&#x722C;&#x53F0;&#x9636;&#x7684;&#x5B9E;&#x73B0;&#x601D;&#x8DEF;"><i
                        class="fa fa-link" aria-hidden="true"></i></a>
                    <p id="algorithm-15">&#x2605;&#x2605;
                      &#x722C;&#x53F0;&#x9636;&#x7684;&#x5B9E;&#x73B0;&#x601D;&#x8DEF;</p>
                  </h3>
                  <blockquote>
                    <p>&#x5047;&#x8BBE;&#x4F60;&#x6B63;&#x5728;&#x722C;&#x697C;&#x68AF;&#x3002;&#x9700;&#x8981; n
                      &#x9636;&#x4F60;&#x624D;&#x80FD;&#x5230;&#x8FBE;&#x697C;&#x9876;&#x3002;</p>
                    <p>&#x6BCF;&#x6B21;&#x4F60;&#x53EF;&#x4EE5;&#x722C; 1 &#x6216; 2
                      &#x4E2A;&#x53F0;&#x9636;&#x3002;&#x4F60;&#x6709;&#x591A;&#x5C11;&#x79CD;&#x4E0D;&#x540C;&#x7684;&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x722C;&#x5230;&#x697C;&#x9876;&#x5462;&#xFF1F;
                    </p>
                    <p>&#x6CE8;&#x610F;&#xFF1A;&#x7ED9;&#x5B9A; n
                      &#x662F;&#x4E00;&#x4E2A;&#x6B63;&#x6574;&#x6570;&#x3002;</p>
                    <p>&#x793A;&#x4F8B; n = 2 ---&gt; 2 &#x4E24;&#x79CD;&#x65B9;&#x6CD5; 1&#x9636; + 1&#x9636; 2&#x9636;
                    </p>
                  </blockquote>
                  <ul>
                    <li>
                      <h4 id="&#x5B9E;&#x73B0;&#x601D;&#x8DEF;"><a name="&#x5B9E;&#x73B0;&#x601D;&#x8DEF;"
                          class="anchor-navigation-ex-anchor" href="#&#x5B9E;&#x73B0;&#x601D;&#x8DEF;"><i
                            class="fa fa-link" aria-hidden="true"></i></a><a name="&#x5B9E;&#x73B0;&#x601D;&#x8DEF;"
                          class="plugin-anchor" href="#&#x5B9E;&#x73B0;&#x601D;&#x8DEF;"><i class="fa fa-link"
                            aria-hidden="true"></i></a>&#x5B9E;&#x73B0;&#x601D;&#x8DEF;</h4>
                    </li>
                  </ul>
                  <pre><code class="lang-javascript"><span class="hljs-comment">// &#x9996;&#x5148;&#x9898;&#x76EE;&#x8981;&#x6C42;&#x679A;&#x4E3E;&#x51FA;&#x6240;&#x6709;&#x722C;&#x697C;&#x68AF;&#x7684;&#x53F0;&#x9636; &#x800C;&#x4E14;&#x53EF;&#x4EE5;&#x4E00;&#x6B21;&#x53EA;&#x722C;&#x4E00;&#x4E2A;&#x53F0;&#x9636;(&#x4E0D;&#x7BA1;&#x600E;&#x4E48;&#x722C;&#x6700;&#x540E;&#x90FD;&#x80FD;&#x53EA;&#x722C;&#x4E00;&#x6B65;&#x5230;&#x8FBE;&#x697C;&#x9876;)</span>
<span class="hljs-comment">// &#x8FD9;&#x662F;&#x53EF;&#x4EE5;&#x7ED9;&#x51FA;&#x4E00;&#x4E2A;&#x57FA;&#x672C;&#x601D;&#x8DEF;  &#x722C;&#x4E00;&#x6B21;(1&#x6216;2) -&gt; &#x722C;&#x5269;&#x4F59;&#x7684;&#x53F0;&#x9636;  &#x7EC8;&#x6B62;&#x6761;&#x4EF6;&#x662F;&#x5269;&#x4F59;&#x53F0;&#x9636;&#x6570;&#x4E3A;0</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">climb</span> (<span class="hljs-params">n</span>) </span>{
  <span class="hljs-keyword">if</span> (n === <span class="hljs-number">0</span>) <span class="hljs-keyword">return</span> <span class="hljs-number">1</span>  <span class="hljs-comment">// &#x8FD9;&#x91CC;&#x8FD4;&#x56DE;&#x4E00;&#x6B21; &#x4EE3;&#x8868;&#x53EF;&#x4EE5;&#x722C;&#x5230;&#x697C;&#x9876;&#x7684;&#x4E00;&#x79CD;&#x65B9;&#x6CD5;</span>
  climb(n - <span class="hljs-number">1</span>)  <span class="hljs-comment">// &#x722C;1&#x9636;&#x540E;&#x722C;&#x5269;&#x4F59;&#x7684;&#x53F0;&#x9636;</span>
  <span class="hljs-keyword">if</span> (n - <span class="hljs-number">2</span> &gt;= <span class="hljs-number">0</span>) {
      climb(n - <span class="hljs-number">2</span>)  <span class="hljs-comment">// &#x722C;2&#x9636;&#x540E;&#x722C;&#x5269;&#x4F59;&#x7684;&#x53F0;&#x9636; &#x8FD9;&#x65F6;&#x5019;&#x8981;&#x5224;&#x65AD;&#x5269;&#x4F59;&#x53F0;&#x9636;&#x6570;&#x662F;&#x4E0D;&#x662F;&#x5927;&#x4E8E;&#x7B49;&#x4E8E;2      </span>
  }
}

<span class="hljs-comment">// &#x6539;&#x8FDB;&#x4E00;&#x4E0B;  &#x7EC8;&#x6B62;&#x6761;&#x4EF6;&#x8BBE;&#x4E3A; n &lt;= 2</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">climb</span> (<span class="hljs-params">n</span>) </span>{
  <span class="hljs-keyword">if</span> (n &lt;= <span class="hljs-number">0</span>) <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>    <span class="hljs-comment">// &#x76F4;&#x63A5;&#x7EC8;&#x6B62;</span>
  <span class="hljs-keyword">if</span> (n &lt;= <span class="hljs-number">2</span>) <span class="hljs-keyword">return</span> n    <span class="hljs-comment">// &#x5269;&#x4F59;1&#x9636;&#x6709;&#x4E00;&#x79CD;&#x89E3;&#x6CD5; 2&#x9636;&#x6709;&#x4E24;&#x79CD;&#x89E3;&#x6CD5;</span>

  <span class="hljs-keyword">return</span> climb(n - <span class="hljs-number">1</span>) + climb(n - <span class="hljs-number">2</span>)
}

<span class="hljs-comment">// &#x6B64;&#x65F6;&#x53EF;&#x4EE5;&#x53D1;&#x73B0;climb(n - 1)&#x5185;&#x90E8;&#x53C8;&#x8C03;&#x7528;&#x4E86;climb(n - 2) &#x800C; climb(n)&#x4E5F;&#x8C03;&#x7528;&#x4E86;climb(n - 2)</span>
<span class="hljs-comment">// &#x4E0D;&#x59A8;&#x4FDD;&#x5B58;&#x4E00;&#x4E0B;&#x8BA1;&#x7B97;&#x7ED3;&#x679C;</span>
<span class="hljs-keyword">let</span> cache = {}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">climb</span> (<span class="hljs-params">n</span>) </span>{
  <span class="hljs-keyword">if</span> (n &lt;= <span class="hljs-number">0</span>) <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>    <span class="hljs-comment">// &#x76F4;&#x63A5;&#x7EC8;&#x6B62;</span>
  <span class="hljs-keyword">if</span> (n &lt;= <span class="hljs-number">2</span>) <span class="hljs-keyword">return</span> n    <span class="hljs-comment">// &#x5269;&#x4F59;1&#x9636;&#x6709;&#x4E00;&#x79CD;&#x89E3;&#x6CD5; 2&#x9636;&#x6709;&#x4E24;&#x79CD;&#x89E3;&#x6CD5;</span>
  <span class="hljs-keyword">if</span> (cache[n]) <span class="hljs-keyword">return</span> cache[n]

  <span class="hljs-keyword">return</span> cache[n] = climb(n - <span class="hljs-number">1</span>) + climb(n - <span class="hljs-number">2</span>)
}
<span class="hljs-comment">// &#x5927;&#x529F;&#x544A;&#x6210;</span>
</code></pre>


                </section>

              </div>
              <div class="search-results">
                <div class="has-results">

                  <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span
                      class='search-query'></span>"</h1>
                  <ul class="search-results-list"></ul>

                </div>
                <div class="no-results">

                  <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>

                </div>
              </div>
            </div>

          </div>
        </div>

      </div>



      <a href="../handwritten/" class="navigation navigation-prev " aria-label="Previous page: 手写代码">
        <i class="fa fa-angle-left"></i>
      </a>


      <a href="../others/" class="navigation navigation-next " aria-label="Next page: 综合">
        <i class="fa fa-angle-right"></i>
      </a>



    </div>

    <script>
      var gitbook = gitbook || [];
      gitbook.push(function () {
        gitbook.page.hasChanged({ "page": { "title": "高频算法", "level": "1.14", "depth": 1, "next": { "title": "综合", "level": "1.15", "depth": 1, "path": "others/index.md", "ref": "./others/index.md", "articles": [] }, "previous": { "title": "手写代码", "level": "1.13", "depth": 1, "path": "handwritten/index.md", "ref": "./handwritten/index.md", "articles": [] }, "dir": "ltr" }, "config": { "plugins": ["-sharing", "splitter", "expandable-chapters-small", "anchors", "github", "github-buttons", "sharing-plus", "anchor-navigation-ex", "favicon", "insert-logo"], "styles": { "website": "./styles/website.css" }, "pluginsConfig": { "github": { "url": "https://github.com/lurongtao/felixbooks-interview" }, "splitter": {}, "search": {}, "sharing-plus": { "qq": false, "all": ["facebook", "google", "twitter", "instapaper", "linkedin", "pocket", "stumbleupon"], "douban": false, "facebook": true, "weibo": false, "instapaper": false, "whatsapp": false, "hatenaBookmark": false, "twitter": true, "messenger": false, "line": false, "vk": false, "pocket": true, "google": false, "viber": false, "stumbleupon": false, "qzone": false, "linkedin": false }, "lunr": { "maxIndexSize": 1000000, "ignoreSpecialCharacters": false }, "fontsettings": { "theme": "white", "family": "sans", "size": 2 }, "highlight": {}, "anchor-navigation-ex": { "associatedWithSummary": true, "float": { "floatIcon": "fa fa-navicon", "level1Icon": "", "level2Icon": "", "level3Icon": "", "showLevelIcon": false }, "mode": "float", "multipleH1": true, "pageTop": { "level1Icon": "", "level2Icon": "", "level3Icon": "", "showLevelIcon": false }, "printLog": false, "showGoTop": true, "showLevel": false }, "favicon": { "shortcut": "./source/images/favicon.jpg", "bookmark": "./source/images/favicon.jpg", "appleTouch": "./source/images/apple-touch-icon.jpg", "appleTouchMore": { "120x120": "./source/images/apple-touch-icon.jpg", "180x180": "./source/images/apple-touch-icon.jpg" } }, "github-buttons": { "buttons": [{ "user": "lurongtao", "repo": "felixbooks-interview", "type": "star", "size": "small", "count": true }] }, "expandable-chapters-small": {}, "sharing": { "qq": false, "all": ["google", "facebook", "weibo", "twitter", "qq", "qzone", "linkedin", "pocket"], "douban": false, "facebook": false, "weibo": false, "instapaper": false, "whatsapp": false, "hatenaBookmark": false, "twitter": false, "messenger": false, "line": false, "vk": false, "pocket": false, "google": false, "viber": false, "stumbleupon": false, "qzone": false, "linkedin": false }, "theme-default": { "styles": { "website": "styles/website.css", "pdf": "styles/pdf.css", "epub": "styles/epub.css", "mobi": "styles/mobi.css", "ebook": "styles/ebook.css", "print": "styles/print.css" }, "showLevel": false }, "anchors": {}, "insert-logo": { "url": "/felixbooks-interview2/images/logo-interview.png", "style": "background: skyblue; width: 100%; height: 100%;" } }, "theme": "default", "author": "码路", "pdf": { "pageNumbers": true, "fontSize": 12, "fontFamily": "Arial", "paperSize": "a4", "chapterMark": "pagebreak", "pageBreaksBefore": "/", "margin": { "right": 62, "left": 62, "top": 56, "bottom": 56 } }, "structure": { "langs": "LANGS.md", "readme": "README.md", "glossary": "GLOSSARY.md", "summary": "SUMMARY.md" }, "variables": {}, "title": "码路大前端小册-企业面试真题", "language": "zh-hans", "links": {}, "gitbook": "3.2.3", "description": "Electron 入门与实战" }, "file": { "path": "algorithm/index.md", "mtime": "2023-05-06T23:22:47.647Z", "type": "markdown" }, "gitbook": { "version": "3.2.3", "time": "2023-05-06T23:31:20.692Z" }, "basePath": "..", "book": { "language": "" } });
      });
    </script>
  </div>


  <script src="../gitbook/gitbook.js"></script>
  <script src="../gitbook/theme.js"></script>


  <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>



  <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>



  <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>



  <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>



  <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>



  <script src="../gitbook/gitbook-plugin-insert-logo/plugin.js"></script>



  <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>



  <script src="../gitbook/gitbook-plugin-search/search.js"></script>



  <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>



  <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>



  <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>



</body>

</html>